package zlx.service.Impl;

import org.springframework.stereotype.Service;
import zlx.mapper.BookMapper;
import zlx.pojo.Book;
import zlx.pojo.Page;
import zlx.service.BookService;

import javax.annotation.Resource;
import java.util.List;

@Service(value = "bookService")
public class BookServiceImpl implements BookService {
    @Resource
    private BookMapper bookMapper;


    //查询所有图书信息
    @Override
    public Page<Book> selectAllBook(Integer pageNo) {
        Integer totalCount = bookMapper.countAllBook();
        Page page=new Page(totalCount,null,null,pageNo);
        List<Book> books = bookMapper.selectAllBook(page.getStart(),page.getPageSize());
        page.setItems(books);
        return page;
    }

    //增加图书
    @Override
    public void addBook(Book book) {
        bookMapper.addBook(book);
    }

    //根据id删除图书
    @Override
    public void deleteBookById(Integer id) {
        bookMapper.deleteBookById(id);
    }

    //根据id查找图书
    @Override
    public Book queryBookById(Integer id) {
        return bookMapper.queryBookById(id);
    }
    //根据id修改图书
    @Override
    public void updateBookById(Book book) {
        bookMapper.updateBookById(book);
    }
}
